//
//  BusinessDetailViewController.m
//  bitcoin
//
//  Created by  旺链 on 2018/5/29.
//  Copyright © 2018年 比特币. All rights reserved.
//

#import "BusinessDetailViewController.h"
#import "HistoryDeputeTableViewCell.h"
#import "BussinessDetailTableViewCell.h"

@interface BusinessDetailViewController ()<UITableViewDelegate,UITableViewDataSource>

@property(nonatomic,strong)UIView *headView;

@property(nonatomic,strong)UITableView *table;

@property(nonatomic,strong)NSMutableArray *dataArr;

@end

@implementation BusinessDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"成交明细 ";
    
    [self.view addSubview:self.table];
    [self getData];
}
- (void)getData
{
    NSString *businessType = [self.data[@"businessType"]isEqualToString:@"买入"]?@"1":@"2";
    NSDictionary *para = @{@"orderId":self.data[@"id"],@"relationId":self.data[@"relationId"],@"businessType":businessType};
    [LSRequestManager postRequestWithURL:MARKET(@"listTradeDetail") params:para success:^(NSDictionary *responseData) {
       
        HandleResponse(
        
                       [self.dataArr addObjectsFromArray:responseData[@"data"]];
                       [self.table reloadData];
                       )}
    } failure:^(NSError *error) {
        
    }];
}
- (UIView *)headView
{
    if (!_headView) {
        _headView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 185)];
        
        HistoryDeputeTableViewCell *cell = [[[NSBundle mainBundle]loadNibNamed:@"HistoryDeputeTableViewCell" owner:self options:nil]firstObject];
        [cell.detailBtn removeFromSuperview];
        
        cell.frame = CGRectMake(0, 0, ScreenWidth, 175);
        [cell configWidthData:self.data];
        
        [_headView addSubview:cell];
        
        UIView *line = [[UIView alloc]init];
        [_headView addSubview:line];
        [line mas_makeConstraints:^(MASConstraintMaker *make) {
            make.height.equalTo(11);
            make.left.bottom.right.equalTo(0);
        }];
        line.backgroundColor = [UIColor colorWithHexString:@"#2E3145"];
    }
    return _headView;
}
- (UITableView *)table
{
    if (!_table) {
        _table = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, self.view.mm_height-(NavgationHeight)) style:UITableViewStylePlain];
        
        _table.backgroundColor = [UIColor colorWithHexString:@"#1C2035"];
        _table.delegate = self;
        _table.dataSource = self;
        _table.tableHeaderView = self.headView;
        _table.tableFooterView = [UIView new];
        [_table registerNib:[UINib nibWithNibName:@"BussinessDetailTableViewCell" bundle:nil] forCellReuseIdentifier:@"BussinessDetailTableViewCell"];
    }
    return _table;
}
- (NSMutableArray *)dataArr
{
    if (!_dataArr) {
        _dataArr = [NSMutableArray array];
    }
    return _dataArr;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    BussinessDetailTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"BussinessDetailTableViewCell"];
    
    NSDictionary *dic = self.dataArr[indexPath.row];
    [cell configWidthData:dic];
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.dataArr.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 155;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
